package com.example.dou2204.live;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.dou2204.R;
import com.example.dou2204.entity.GiftEntity;

public class GiftLayout extends LinearLayout {
    TextView tvUser,tvGift,tvCount;
    ImageView ivUser,ivGift;
    public GiftLayout(Context context) {
        super(context);
    }

    public GiftLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View inflate = LayoutInflater.from(context).inflate(R.layout.layout_gift, null);
        tvUser = inflate.findViewById(R.id.tv_user);
        tvGift = inflate.findViewById(R.id.tv_gift);
        tvCount = inflate.findViewById(R.id.tv_count);

        ivUser = inflate.findViewById(R.id.iv_user);
        ivGift = inflate.findViewById(R.id.iv_gift);
        addView(inflate);//将布局添加到总的页面中
    }

    public GiftLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public GiftLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void loadUser(String url){
        Glide.with(getContext()).load(url).into(ivUser);
    }
    public void loadUsername(String name){
        tvUser.setText(name+"");
    }
    public void loadCount(int count){
        tvCount.setText("X"+count);
    }
    public void loadGift(GiftEntity.DataBean dataBean){
        Glide.with(getContext()).load(dataBean.getGiftpath()).into(ivGift);
        tvGift.setText(dataBean.getGiftname()+"");
    }
}
